import type { Ref } from 'vue'
import {ref} from 'vue'
export default class countDown {
    controller: Ref<boolean>
    display: Ref<number>=ref(0)
    display2: Ref<number>=ref(0)
    clear: any
    constructor(controller: Ref<boolean>, display:number) {
        this.controller = controller
        this.display.value = display
        this.display2.value = display
    }
    /**
     * 开始倒计时
     */
    down(fun: Function) {
        if (this.clear)
            return
        fun()
        this.controller.value = false
        this.clear = setInterval(() => {
            this.display.value--
            if (this.display.value <= 0) {
                this.controller.value = true
                clearInterval(this.clear)
                this.clear = null
                this.display.value = this.display2.value
            }
        }, 1000)
    }
}